package org.dczl.system.controller.daping;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import org.dczl.common.core.domain.R;
import org.dczl.common.idempotent.annotation.RepeatSubmit;
import org.dczl.common.mybatis.core.page.PageQuery;
import org.dczl.common.mybatis.core.page.TableDataInfo;
import org.dczl.common.web.core.BaseController;
import org.dczl.system.domain.vo.DpDevice;
import org.dczl.system.service.IDpDeviceService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;


/**
 * 设备管理
 * 前端访问路由地址为:/core/device
 *
 * @author jia
 * @date 2025-04-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device")
public class DpDeviceController extends BaseController {

    private final IDpDeviceService dpDeviceService;

    /**
     * 查询设备列表
     */
    @GetMapping("/list")
    public TableDataInfo<DpDevice> list(DpDevice bo, PageQuery pageQuery) {
        return dpDeviceService.queryPageList(bo, pageQuery);
    }

    /**
     * 新增设备
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@RequestBody DpDevice bo) {
        return toAjax(dpDeviceService.insertByBo(bo));
    }

    /**
     * 修改设备
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@RequestBody DpDevice bo) {
        return toAjax(dpDeviceService.updateByBo(bo));
    }

    /**
     * 删除设备
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(dpDeviceService.deleteWithValidByIds(List.of(ids), true));
    }
}
